package at.ac.tuwien.infosys.aic11.services;

import at.ac.tuwien.infosys.aic11.dto.CreditRequest;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import at.ac.tuwien.infosys.aic11.fault.UnknownAddressFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownCustomerFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownDisbursementPreferenceFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownMoneyFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownOfferFault;
import at.ac.tuwien.infosys.aic11.fault.UnknownRequestFault;

import javax.faces.bean.ApplicationScoped;
import javax.inject.Named;
import java.io.Serializable;

/**
 * Created by IntelliJ IDEA.
 * User: gh
 * Date: 08.11.11
 * Time: 12:26
 * To change this template use File | Settings | File Templates.
 */
@ApplicationScoped
@Named
public class ShipmentServiceClient implements Serializable{

	private static final long serialVersionUID = 1L;
	ShippingService shippingService = null;


	public ShipmentServiceClient(){

		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.getInInterceptors().add(new LoggingInInterceptor());
		factory.getOutInterceptors().add(new LoggingOutInterceptor());
		factory.setServiceClass(ShippingService.class);
		factory.setAddress("http://localhost:9001/ShippingService");
		shippingService = (ShippingService) factory.create();
	}


	public void notifyPerMail(){
		shippingService.notifyPerMail();
	}

	public boolean finaliseContract(CreditRequest creditRequest) throws UnknownRequestFault, UnknownCustomerFault, UnknownDisbursementPreferenceFault, UnknownMoneyFault, UnknownAddressFault, UnknownOfferFault {
		return shippingService.finaliseContract(creditRequest);
	}
}
